public Form1{ //some code... AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit); } public void OnProcessExit(object sender,EventArgs e){ MyDataLoggerMethod("Monitoring ended."); }